import React from "react"
import { View } from "react-native"
import { Color, Jpp, Label, Lt, Dialog, Navigator } from "../_utils";
import { cHome } from '../home/_home';

export const eRole = Object.freeze({
    ZERO:0,CARRIER:1,AGENT:2,FANS:3,
    names:["", "运营商", "代理", "粉丝",],
})

export class cMe{
    static toPrice(price){
        return cHome.toPrice(price, 100);
    }

    static fansMsg(roleId, title, nav){
        if(roleId === eRole.FANS){
            Dialog.msg2(title + " 是 " + eRole.names[eRole.CARRIER] + "/" + eRole.names[eRole.AGENT] + " 特权, 请前往 会员中心 申请成为 " + eRole.names[eRole.CARRIER], ()=>{
                if(nav){
                    Navigator.navigate(nav, "PageVip");
                }
            }, null, "好的");
            return true;
        }
        return false;
    }

    static toMe(data){
        data.myMoney = this.toPrice(data.myMoney);
        data.myTeamMoney = this.toPrice(data.myTeamMoney);
        return data;
    }
    
    static toChild(data){
        data.yesMonday = this.toPrice(data.yesMonday);  //本月贡献佣金
        data.yesday = this.toPrice(data.yesday); // 昨日贡献佣金
        data.today = this.toPrice(data.today); //今日贡献佣金
        data.lastMonday = this.toPrice(data.lastMonday); //昨月贡献佣金
        return data;
    }

    static toCash(data){
        data.waitMoney = this.toPrice(data.waitMoney);
        data.finishMoney = this.toPrice(data.finishMoney);
        data.cash = this.toPrice(data.cash);
        return data;
    }

    static toIncome(data){
        data.inCome = this.toPrice(data.inCome);//预估总收益

        data.today = this.toPrice(data.today);//今日预估收益
        data.yesday = this.toPrice(data.yesday);//昨日预估收益
        data.yesMonday = this.toPrice(data.yesMonday);//本月预估收益	
        data.lastMonday = this.toPrice(data.lastMonday);//上月预估收益

        data.todaySettle = this.toPrice(data.todaySettle);//今日结算
        data.yesdaySettle = this.toPrice(data.yesdaySettle);//昨日结算	
        data.yesMondaySettle = this.toPrice(data.yesMondaySettle);//本月结算
        data.lastMondaySettle = this.toPrice(data.lastMondaySettle);//上月结算	
        return data;
    }
}

export class LabelHead extends React.PureComponent{
    render(){
        const {style, title, titleStyle, contentStyle, children} = this.props;
        return <View style={{flex:1, height:40, justifyContent:"center", alignItems:"center", ...style}}>
            <Label style={{fontSize:Lt.c20, color:"white", ...contentStyle}}>{children}</Label>
            <Label style={{fontSize:Lt.c16, color:Color.whiteOpacity, marginTop:Lt.margin, ...titleStyle}}>{title}</Label>
        </View>
    }
}


export class ViewReport extends React.PureComponent{
    render(){
        const {style, date, fields, values} = this.props;
        const prop = {
            style:{height:80},
            titleStyle:{color:Color.c9},
            contentStyle:{color:Color.theme},
        }
        return <View style={{margin:Lt.margin, marginTop:0, borderRadius:Lt.radiu2, backgroundColor:"white", flexDirection:"row", ...style}}>
            <View style={{padding:Lt.pad, borderTopLeftRadius:Lt.radiu2, borderBottomLeftRadius:Lt.radiu2, justifyContent:"center", backgroundColor:"#EFEFEF"}}>
                <Label style={{fontSize:Lt.c18, color:Color.c3}}>{date}</Label>
            </View>
            {
                fields.map((v,i)=>{
                    return <LabelHead key={i} title={v} {...prop}>{values[i]}</LabelHead>
                })
            }
        </View>
    }
}